package com.lzy.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lzy.annotation.AuthCheck;
import com.lzy.service.ISysDeptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lzy.common.R;
import com.lzy.entity.SysDeptEntity;

/**
 * 部门表
 *
 * @author lyw
 * @email lyw@gmail.com
 * @date 2023-02-27 20:34:44
 */
@RestController
@RequestMapping("/sysdept")
public class SysDeptController {
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation(value = "角色列表")
    @AuthCheck(hasAuthority = "system:dept:list")
    public R list(@RequestBody SysDeptEntity sysDeptEntity){
        List<SysDeptEntity> list = sysDeptService.selectPageList(sysDeptEntity);
        return R.ok().put("page", list);
    }

    /**
     * tree 结构
     */
    @RequestMapping("/treelist")
    @ApiOperation(value = "角色列表")
    @AuthCheck(hasAuthority = "system:dept:list")
    public R treelist(@RequestBody SysDeptEntity sysDeptEntity){
        List<SysDeptEntity> list = sysDeptService.selectPageTreeList(sysDeptEntity);
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{deptId}")
    // @RequiresPermissions(".:sysdept:info")
    public R info(@PathVariable("deptId") Long deptId){
		SysDeptEntity sysDept = sysDeptService.getById(deptId);

        return R.ok().put("sysDept", sysDept);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions(".:sysdept:save")
    public R save(@RequestBody SysDeptEntity sysDept){
		sysDeptService.save(sysDept);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions(".:sysdept:update")
    public R update(@RequestBody SysDeptEntity sysDept){
		sysDeptService.updateById(sysDept);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions(".:sysdept:delete")
    public R delete(@RequestBody Long[] deptIds){
		sysDeptService.removeByIds(Arrays.asList(deptIds));

        return R.ok();
    }

}
